package com.cxhc.system.service.hcdoc.impl;

import com.cxhc.common.core.domain.entity.SysUser;
import com.cxhc.common.utils.StringUtils;
import com.cxhc.system.domain.hcdoc.HdUserInfo;
import com.cxhc.system.mapper.hcdoc.HcDocUserMapper;
import com.cxhc.system.service.hcdoc.HcDocUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;


/**
 * 用户 业务层处理
 *
 * @author Dhq
 */
@Service
public class HcDocUserServiceImpl implements HcDocUserService {

    @Autowired
    private HcDocUserMapper hcDocUserMapper;



    @Override
    public HdUserInfo selectUserByAccountNoForHCDoc(String accountNo) {
        return hcDocUserMapper.selectuserInfoByAccountNo(accountNo);
    }

    @Override
    public int insertHcUser(HdUserInfo hdUserInfo) {
        HdUserInfo hdUserInfoTemp = hcDocUserMapper.selectuserInfoByAccountNoForInsert(hdUserInfo.getAccountNo());
        if (!ObjectUtils.isEmpty(hdUserInfoTemp)){
            if ("1".equals(hdUserInfoTemp.getIsDelete())){
                hdUserInfo.setIsDelete("0");
                return hcDocUserMapper.update(hdUserInfo);
            }
            throw new RuntimeException("用户已存在!!!");
        }
        return hcDocUserMapper.insert(hdUserInfo);
    }

    @Override
    public List<HdUserInfo> selectList(HdUserInfo hdUserInfo) {
        return hcDocUserMapper.selectListByBranch(hdUserInfo);
    }

    @Override
    public int update(HdUserInfo hdUserInfo) {
        return hcDocUserMapper.update(hdUserInfo);
    }

    @Override
    public int delete(String accountNo) {

        return hcDocUserMapper.updateIsDelete(accountNo);
    }
}
